﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using FirstFloor.ModernUI.Presentation;
using System.Xml;

namespace ModernWSPView.Classes.Converters
{
    public class XmlListToMuiLinkCollection: IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            LinkCollection result = null;

            foreach (object value in values)
            {
                if (value is XmlElement)
                {
                    XmlElement xe = value as XmlElement;

                    //===============================================================
                    if (xe.Name == "ContentType")
                    {
                        string url = string.Format(
                            "Pages/PageListFieldsOfContentType.xaml#{0}",
                            ((XmlElement)value).Attributes["ID"].Value);

                        Link buffer = new Link()
                        {
                            DisplayName = ((XmlElement)value).Attributes["Name"].Value,
                            Source = new Uri(url, UriKind.RelativeOrAbsolute)
                        };

                        result.Add(buffer);
                    }
                    //===============================================================
                }
            }

            return result;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
}
